package com.schoolvisitors.repository;

import com.schoolvisitors.entity.InstrumentLoan;
import com.schoolvisitors.entity.User;
import com.schoolvisitors.enums.InstrumentLoanStatusEnum;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface InstrumentLoanRepository extends JpaRepository<InstrumentLoan, Long> {
    boolean existsByInstrumentIdAndStatus(Long id, InstrumentLoanStatusEnum instrumentLoanStatusEnum);

    boolean existsByUserIdAndInstrumentIdAndStatus(Long userId, Long instrumentId, InstrumentLoanStatusEnum instrumentLoanStatusEnum);

    Page<InstrumentLoan> findByUserAndStatus(User user, InstrumentLoanStatusEnum instrumentLoanStatusEnum, Pageable pageable);

    Page<InstrumentLoan> findByUserAndStatusNot(User user, InstrumentLoanStatusEnum instrumentLoanStatusEnum, Pageable pageable);

    Page<InstrumentLoan> findByReviewerIdAndStatus(Long reviewerId, InstrumentLoanStatusEnum status, Pageable pageable);

    Page<InstrumentLoan> findByReviewerId(long reviewerId, Pageable pageable);

    InstrumentLoan findByUserAndStatusAndId(User user, InstrumentLoanStatusEnum status, Long id);

    InstrumentLoan findByUserAndId(User user, Long id);
}
